package com.ChenYaRou.www.controller.servlet;

import com.ChenYaRou.www.controller.RegisterServletController;
import com.ChenYaRou.www.po.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName RegisterFinallyServlet
 * @Description TODO
 * @Author 86183
 * @Date 2022/5/3 18:09
 * @Version 1.0
 **/
public class RegisterFinallyServlet extends BaseServlet {

    public void registerFinally(HttpServletRequest req, HttpServletResponse resp){
        try {
            PrintWriter out = resp.getWriter();
            JSONObject userInput = JSON.parseObject(req.getParameter("json"));
            out.write(new RegisterServletController().registerFinally(
                    new User(userInput.getString("name"),
                            userInput.getString("password"), userInput.getString("state"))));
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
